def findPeakElement(nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    if not nums:
        return 0
    left, right = 0, len(nums) - 1
    while left <= right:
        mid = left + (right - left) // 2
        if mid + 1 >= len(nums):
            return mid
        if nums[mid] > nums[mid + 1]:
            right = mid - 1
        else:
            left = mid + 1
    return left


nums = [4, 3, 2, 1]
print(findPeakElement(nums))
